package com.zhiche.lisa.lspm.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import com.zhiche.lisa.core.utils.Account.AccountUtil;
import com.zhiche.lisa.core.utils.Account.JwtAccountVO;
import com.zhiche.lisa.lspm.dao.model.carrier.CarrierInfo;
import com.zhiche.lisa.lspm.dao.model.driver.Driver;
import com.zhiche.lisa.lspm.dao.model.fleet.Fleet;
import com.zhiche.lisa.lspm.dao.model.lsp.LspInfo;
import com.zhiche.lisa.lspm.dao.model.trailer.TrailerInfo;
import com.zhiche.lisa.lspm.dto.ArFundDTO;
import com.zhiche.lisa.lspm.service.fleet.IFleetBindService;
import com.zhiche.lisa.lspm.service.fleet.IFleetService;
import com.zhiche.lisa.lspm.service.lsp.LspInfoService;
import com.zhiche.lisa.lspm.vo.fleet.FleetBindVO;
import com.zhiche.lisa.lspm.vo.fleet.FleetLineVO;
import com.zhiche.lisa.lspm.vo.fleet.FleetManagementListVO;
import com.zhiche.lisa.lspm.vo.fleet.FleetVo;
import com.zhiche.lisa.lspm.vo.vehicle.CarrierBasicVO;
import com.zhiche.lisa.lspm.vo.vehicle.TrailerBasicVO;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@RestController
@RequestMapping(value = "/fleet")
@Api(value = "/fleet", description = "公司车队接口", tags = {"公司车队接口"})
public class FleetController {
    private static final Logger LOGGER = LoggerFactory.getLogger(FleetController.class);
    @Autowired
    private IFleetService fleetService;
    @Autowired
    private IFleetBindService fleetBindService;
    @Autowired
    private LspInfoService lspInfoService;

    @PostMapping(value = "/fleetLine")
    @ApiOperation(value = "获取公司车队列表", notes = "获取公司车队列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "lspName", value = "承运商名称", required = false, dataType =
//                    "String"),
//            @ApiImplicitParam(name = "fleetName", value = "车队名称", required = false, dataType =
//                    "String")})
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = FleetLineVO.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<FleetLineVO>> fleetLine(@RequestBody @ApiParam(name = "车队分页查询对象", value = "传入json格式", required = true) Page<FleetLineVO> page,
                                                        @RequestHeader("Authorization") String authorization) {
        LOGGER.info("FleetController.fleetLine（获取公司车队列表） params : {} ", page);

        RestfulResponse<Page<FleetLineVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            Page<FleetLineVO> pageVo = fleetService.fleetLinePage(page, authorization);
            result.setData(pageVo);
        } catch (BaseException e) {
            LOGGER.error("FleetController.fleetLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.fleetLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/selectFleetList")
    @ApiOperation(value = "获取公司车队列表", notes = "获取公司车队列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Fleet.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<Fleet>> selectFleetList(@RequestBody @ApiParam(name = "车队分页查询对象", value = "传入json格式", required = true) Map<String, Object> condition) {
        LOGGER.info("FleetController.selectFleetList（获取公司车队列表） params : {} ", condition);

        RestfulResponse<List<Fleet>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            List<Fleet> pageVo = fleetService.selectFleetList(condition);
            result.setData(pageVo);
        } catch (BaseException e) {
            LOGGER.error("FleetController.selectFleetList ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.selectFleetList ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/lspFleetLine")
    @ApiOperation(value = "获取承运商车队列表", notes = "获取承运商车队列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = FleetLineVO.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<FleetLineVO>> lspFleetLinePage(@RequestBody @ApiParam(name = "车队分页查询对象", value = "传入json格式", required = true) Page<FleetLineVO> page,
                                                               @RequestHeader("Authorization") String authorization) {
        LOGGER.info("FleetController.lspFleetLine（获取承运商车队列表） params : {} ", page);
        RestfulResponse<Page<FleetLineVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            Page<FleetLineVO> pageVo = fleetService.lspFleetLinePage(page, authorization);
            result.setData(pageVo);
        } catch (BaseException e) {
            LOGGER.error("FleetController.lspFleetLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.lspFleetLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping(value = "/listLspInfo")
    @ApiOperation(value = "根据名称获取公司", notes = "根据名称获取公司", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = LspInfo.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<LspInfo>> listLspInfo(@ApiParam(name = "corpName", value = "模糊名称", required = true) String corpName) {
        RestfulResponse result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        EntityWrapper<LspInfo> ew = new EntityWrapper<>();
        ((EntityWrapper) ew).like("name", corpName);
        JwtAccountVO jwtAccountVO = null;
        if (Objects.isNull(jwtAccountVO = AccountUtil.getAccountInfoFromSecurityContext())) {
            return new RestfulResponse<>(CommonEnum.ERROR.getCode(), "未获取到用户登录信息", null);
        }
        ((EntityWrapper) ew).ne("tenant_id", jwtAccountVO.getTenantId());
        result.setData(lspInfoService.selectList(ew));
        return result;
    }

    @GetMapping(value = "/listFleetInfo")
    @ApiOperation(value = "根据名称获取车队", notes = "根据名称获取车队", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Fleet.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<Fleet>> listFleetInfo(
            @RequestParam("corpName") @ApiParam(name = "corpName", value = "模糊名称", required = true) String corpName,
            @RequestParam(value = "lspId", required = false) @ApiParam(name = "lspId", value = "承运商id", required = false) Long lspId,
            @RequestParam(value = "fleetAttribute", required = false) @ApiParam(name = "lspId", value = "承运商id", required = false) Integer fleetAttribute) {
        RestfulResponse result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        EntityWrapper<Fleet> ew = new EntityWrapper<>();
        ew.like("fleet_name", corpName);
        JwtAccountVO jwtAccountVO = null;
        if (Objects.isNull(jwtAccountVO = AccountUtil.getAccountInfoFromSecurityContext())) {
            return new RestfulResponse<>(CommonEnum.ERROR.getCode(), "未获取到用户登录信息", null);
        }
        if (Objects.nonNull(lspId)) {
            ew.eq("lsp_id", lspId);
        }
        if (Objects.nonNull(fleetAttribute)) {
            ew.eq("fleet_attribute", fleetAttribute);
        }

        ((EntityWrapper) ew).ne("tenant_id", jwtAccountVO.getTenantId());
        result.setData(fleetService.selectList(ew));
        return result;
    }


    @GetMapping(value = "/getPersonalByLsp")
    @ApiOperation(value = "根据名称获取车队", notes = "根据名称获取车队", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Fleet.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<String>> getPersonalByLsp(
            @RequestParam("lspId") @ApiParam(name = "lspId", value = "承运商id", required = true) Long lspId) {
        RestfulResponse result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        EntityWrapper<Fleet> ew = new EntityWrapper<>();
        ew.setSqlSelect("personal");
        ew.isNotNull("personal");
        ew.groupBy("personal");
        if (lspId != null) {
            ew.eq("lsp_id", lspId);
        }
        result.setData(fleetService.selectObjs(ew));
        return result;
    }

    @PostMapping(value = "/createFleet")
    @ApiOperation(value = "创建车队", notes = "创建车队", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<String> createFleet(@RequestBody @ApiParam(name = "车队保存数据对象", value = "传入json格式", required = true) Fleet fleet, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("FleetController.createFleet（创建车队） params : {} ", fleet);
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            fleetService.insertFleet(fleet, authorization);
        } catch (BaseException e) {
            LOGGER.error("FleetController.createFleet ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.createFleet ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/updateFleet")
    @ApiOperation(value = "更新车队信息", notes = "更新车队信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功", response = Fleet.class),
            @ApiResponse(code = 0, message = "操作失败")})
    public RestfulResponse<Fleet> updateFleet(@RequestBody @ApiParam(name = "车队更新数据对象", value = "传入json格式", required = true) Fleet fleet, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("FleetController.updateFleet（更新车队信息） params : {} ", fleet);
        RestfulResponse<Fleet> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            Fleet updateFleet = fleetService.updateFleet(fleet, authorization);
            result.setData(updateFleet);
        } catch (BaseException e) {
            LOGGER.error("FleetController.updateFleet ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.updateFleet ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/deleteFleet")
    @ApiOperation(value = "删除车队", notes = "删除车队", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<String>> deleteFleet(@RequestBody @ApiParam(name = "删除车队列对象", value = "传入json格式", required = true) FleetLineVO fleetLineVO) {
        LOGGER.info("FleetController.deleteFleet（删除车队） params : {} ", fleetLineVO);
        RestfulResponse<List<String>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            List<String> msg = fleetService.deleteFleet(fleetLineVO.getFleetIds());
            if (!CollectionUtils.isEmpty(msg))
                result = new RestfulResponse<>(CommonEnum.ERRORLIST.getCode(), "部分删除失败", msg);
        } catch (BaseException e) {
            LOGGER.error("FleetController.deleteFleet ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.deleteFleet ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/fleetUnBindLine")
    @ApiOperation(value = "查询未绑定车辆", notes = "查询未绑定车辆", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = FleetBindVO.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<FleetBindVO>> fleetUnBindLine(@RequestBody @ApiParam(name = "车辆信息查询对象", value = "传入json格式", required = true) FleetBindVO fleetBindVO,
                                                              @RequestHeader("Authorization") String authorization) {
        LOGGER.info("FleetController.fleetUnBindLine（查询未绑定车辆） params : {} ", fleetBindVO.toString());
        RestfulResponse<List<FleetBindVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            List<FleetBindVO> fleetCarrierVOS = fleetBindService.queryFleetUnBindLine(fleetBindVO, authorization);
            result.setData(fleetCarrierVOS);
        } catch (BaseException e) {
            LOGGER.error("FleetController.fleetUnBindLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.fleetUnBindLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/fleetBingLine")

    @ApiOperation(value = "查询已绑定车辆", notes = "查询已绑定车辆", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = FleetBindVO.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<FleetBindVO>> fleetBingLine(@RequestBody @ApiParam(name = "车辆分页查询对象", value = "传入json格式", required = true) Page<FleetBindVO> page,
                                                            @RequestHeader("Authorization") String authorization) {
        LOGGER.info("FleetController.fleetBingLine（查询已绑定车辆） params : {} ", page.toString());
        RestfulResponse<Page<FleetBindVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            Page<FleetBindVO> fleetCarrierVOS = fleetBindService.queryFleetBindLine(page, authorization);
            result.setData(fleetCarrierVOS);
        } catch (BaseException e) {
            LOGGER.error("FleetController.fleetBingLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.fleetBingLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/addFleetBind")
    @ApiOperation(value = "增加车辆绑定", notes = "增加车辆绑定", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<String> addCarriers(@RequestBody @ApiParam(name = "车辆新增信息对象", value = "传入json格式", required = true) FleetLineVO fleetLineVO, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("FleetController.addFleetBind（增加车辆绑定） params : {} ", fleetLineVO.toString());
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            fleetService.insertFleetBing(fleetLineVO, authorization);
        } catch (BaseException e) {
            LOGGER.error("FleetController.addFleetBind ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.addFleetBind ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/deleteFleetBind")
    @ApiOperation(value = "删除牵引车绑定", notes = "删除牵引车绑定", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 1, message = "操作失败")})
    public RestfulResponse<String> deleteCarriers(@RequestBody @ApiParam(name = "车辆删除信息对象", value = "传入json格式", required = true) FleetLineVO fleetLineVO) {
        LOGGER.info("FleetController.deleteFleetBind（删除牵引车绑定） params : {} ", fleetLineVO.toString());
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            fleetService.deleteFleetBing(fleetLineVO);
        } catch (BaseException e) {
            LOGGER.error("FleetController.deleteFleetBind ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.deleteFleetBind ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/queryBindDataList/carrier")
    @ApiOperation(value = "查询车队绑定牵引车信息", notes = "查询车队绑定牵引车信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = CarrierInfo.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<CarrierBasicVO>> queryBindDataListCarrier(@RequestBody @ApiParam(name = "车辆绑定信息查询对象", value = "传入json格式", required = true) Page<CarrierInfo> fleetBindsVO) {
        LOGGER.info("FleetController.queryBindDataListCarrier（查询车队绑定牵引车信息） params : {} ", fleetBindsVO.toString());
        RestfulResponse<Page<CarrierBasicVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            Page<CarrierBasicVO> bindList = fleetBindService.queryBindCarrierList(fleetBindsVO);
            result.setData(bindList);
        } catch (BaseException e) {
            LOGGER.error("FleetController.queryBindDataListCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.queryBindDataListCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/queryBindDataList/trailer")
    @ApiOperation(value = "查询车队绑定挂车信息", notes = "查询车队绑定挂车信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = TrailerInfo.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<TrailerBasicVO>> queryBindDataListTrailer(@RequestBody @ApiParam(name = "车辆绑定信息查询对象", value = "传入json格式", required = true) Page<TrailerInfo> fleetBindsVO) {
        LOGGER.info("FleetController.queryBindDataListTrailer（查询车队绑定挂车信息） params : {} ", fleetBindsVO.toString());
        RestfulResponse<Page<TrailerBasicVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            Page<TrailerBasicVO> bindList = fleetBindService.queryBindTrailerWithFleetId(fleetBindsVO);
            result.setData(bindList);
        } catch (BaseException e) {
            LOGGER.error("FleetController.queryBindDataListTrailer ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.queryBindDataListTrailer ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/queryBindDataList/driver")
    @ApiOperation(value = "查询车队绑定司机信息", notes = "查询车队绑定司机信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Driver.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<Driver>> queryBindDataListDriver(@RequestBody @ApiParam(name = "车辆绑定信息查询对象", value = "传入json格式", required = true) Page<Driver> fleetBindsVO) {
        LOGGER.info("FleetController.queryBindDataListDriver（查询车队绑定司机信息） params : {} ", fleetBindsVO.toString());
        RestfulResponse<Page<Driver>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            Page<Driver> bindList = fleetBindService.queryDriverBindWithFleet(fleetBindsVO);
            result.setData(bindList);
        } catch (BaseException e) {
            LOGGER.error("FleetController.queryBindDataListDriver ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.queryBindDataListDriver ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping("/fleetToOtm/{id}")
    @ApiOperation(value = "车队推otm", notes = "车队推otm", produces = MediaType.APPLICATION_JSON_VALUE, response
            = RestfulResponse.class)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "操作失败", response = Object.class)})
    public RestfulResponse<String> fleetUnBindLine(@PathVariable Long id,
                                                   @RequestHeader("Authorization") String authorization) {
        LOGGER.info("FleetController.fleetToOtm（车队推otm） params : {} ", id);
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            result.setData(fleetService.fleetToOtm(id, authorization));
        } catch (BaseException e) {
            LOGGER.error("FleetController.fleetToOtm ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.fleetToOtm ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/getFleetAll")
    @ApiOperation(value = "批量获取车队信息", notes = "批量获取车队信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = FleetLineVO.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<Fleet>> lspFleetLinePage(@RequestBody List<Fleet> fleet) {
        LOGGER.info("FleetController.getFleetAll（批量获取车队信息） params : {} ", fleet);
        RestfulResponse<List<Fleet>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            List<Fleet> fleetAllData = fleetService.getFleetAll(fleet);
            result.setData(fleetAllData);
        } catch (BaseException e) {
            LOGGER.error("FleetController.getFleetAll ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.getFleetAll ERROR... ", e);
        }
        return result;
    }

    @PostMapping(value = "/queryFleetByName")
    @ApiOperation(value = "根据应收款项信息获取车队信息", notes = "根据应收款项信息获取车队信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestfulResponse<Map<Long, Fleet>> queryFleetByName(@RequestBody List<ArFundDTO> arFundDTOS) {
        LOGGER.info("FleetController.queryFleetByName param : {}", arFundDTOS);
        RestfulResponse<Map<Long, Fleet>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(fleetService.queryFleetByName(arFundDTOS));
        } catch (BaseException e) {
            LOGGER.error("FleetController.queryFleetByName ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.queryFleetByName ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/fleetManagementLsit")
    @ApiOperation(value = "所属车队列表", notes = "所属车队列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = FleetLineVO.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<FleetManagementListVO>> fleetManagementLsit(@RequestBody Page<FleetManagementListVO> page,
                                                                            @RequestHeader("Authorization") String authorization) {
        LOGGER.info("FleetController.fleetManagementLsit（所属车队列表） params : {} ", page);

        RestfulResponse<Page<FleetManagementListVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            result.setData(fleetService.FleetManagementList(page, authorization));

        } catch (BaseException e) {
            LOGGER.error("FleetController.fleetManagementLsit ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.fleetManagementLsit ERROR... ", e);
        }
        return result;
    }

    @PostMapping(value = "/getOneFleet")
    @ApiOperation(value = "获取单个车队信息", notes = "获取单个车队信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功", response = Fleet.class),
            @ApiResponse(code = 0, message = "操作失败")})
    public RestfulResponse<FleetLineVO> getOneFleet(@RequestBody @ApiParam(name = "车队数据对象", value = "传入json格式", required = true) Fleet fleet) {
        LOGGER.info("FleetController.getOneFleet（获取单个车队信息） params : {} ", fleet);
        RestfulResponse<FleetLineVO> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            FleetLineVO fleetLineVO = new FleetLineVO();
            Fleet oneFleet = fleetService.getOneFleet(fleet);
            LspInfo lspInfo = lspInfoService.selectById(oneFleet.getLspId());
            BeanUtils.copyProperties(oneFleet, fleetLineVO);
            fleetLineVO.setLspName(lspInfo.getName());
            result.setData(fleetLineVO);
        } catch (BaseException e) {
            LOGGER.error("FleetController.getOneFleet ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.getOneFleet ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping(value = "/getFleetByIdNoTenant/{id}")
    @ApiOperation(value = "根据车队id获取车队信息", notes = "根据车队id获取车队信息", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功", response = Fleet.class),
            @ApiResponse(code = 0, message = "操作失败")})
    public RestfulResponse<Fleet> getFleetByIdNoTenant(@PathVariable Long id) {
        LOGGER.info("FleetController.getFleetByIdNoTenant（获取单个车队信息） id : {} ", id);
        RestfulResponse<Fleet> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            result.setData(fleetService.selectByIdNoTenant(id));
        } catch (BaseException e) {
            LOGGER.error("FleetController.getFleetByIdNoTenant error: {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.getFleetByIdNoTenant error: {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping(value = "/getFleetAttach")
    @ApiOperation(value = "获取车队附件信息", notes = "获取车队附件信息", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功", response = Fleet.class),
            @ApiResponse(code = 0, message = "操作失败")})
    public RestfulResponse<Fleet> getFleetAttach(Long id) {
        LOGGER.info("FleetController.updateFleet（获取车队附件信息） params : {} ", id);
        RestfulResponse<Fleet> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            Fleet updateFleet = fleetService.getFleetAttach(id);
            result.setData(updateFleet);
        } catch (BaseException e) {
            LOGGER.error("FleetController.getFleetAttach ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.getFleetAttach ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/getFleetByIds")
    @ApiOperation(value = "根据车队id获取车队及其银行信息", notes = "根据车队id获取车队及其银行信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功", response = Fleet.class),
            @ApiResponse(code = 0, message = "操作失败")})
    public RestfulResponse<List<Fleet>> getFleetByIds(@RequestBody List<Long> ids) {
        LOGGER.info("FleetController.getFleetByIds（获取单个车队及其银行信息） ids : {} ", ids);
        RestfulResponse<List<Fleet>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            result.setData(fleetService.selectFleetByIds(ids));
        } catch (BaseException e) {
            LOGGER.error("FleetController.getFleetByIds error: {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.getFleetByIds error: {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping(value = "/getAttachPatch")
    @ApiOperation(value = "获取附件路径信息", notes = "获取附件路径信息", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功", response = Map.class),
            @ApiResponse(code = 0, message = "操作失败")})
    public RestfulResponse<Map<String,Object>> getAttachPatch(String key) {
        LOGGER.info("FleetController.getAttachPatch（获取车队附件信息） params : {} ", key);
        RestfulResponse<Map<String,Object>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            Map<String,Object> attachPatch = fleetService.getAttachPatch(key);
            result.setData(attachPatch);
        } catch (BaseException e) {
            LOGGER.error("FleetController.getFleetAttach ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.getFleetAttach ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping("/queryFleetBasic")
    public RestfulResponse<FleetLineVO> queryFleetBasic(@RequestBody Map<String, String> condition) {
        RestfulResponse<FleetLineVO> response = new RestfulResponse<>(0, "请求成功", null);
        try {
            FleetLineVO data = fleetService.queryFleetBasic(condition);
            response.setData(data);
        } catch (BaseException be) {
            LOGGER.error("FleetController.queryFleetBasic BaseException: {}", be);
            response.setCode(-1);
            response.setMessage(be.getMessage());
        } catch (Exception e) {
            LOGGER.error("FleetController.queryFleetBasic ERROR {}", e);
            response.setCode(-1);
            response.setMessage("系统异常");
        }
        return response;
    }

    @PostMapping(value = "/selectFleetListByLspMobile")
    @ApiOperation(value = "根据承运商手机获取公司车队列表", notes = "根据承运商手机获取公司车队列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Fleet.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<Fleet>> selectFleetListByLspMobile(@RequestBody  String mobile) {
        LOGGER.info("FleetController.selectFleetListByLspMobile（根据承运商手机获取公司车队列表） params : {} ", mobile);

        RestfulResponse<List<Fleet>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            List<Fleet> fleets = fleetService.selectFleetListByLspMobile(mobile);
            result.setData(fleets);
        } catch (BaseException e) {
            LOGGER.error("FleetController.selectFleetListByLspMobile ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.selectFleetListByLspMobile ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/getFleetListByMobileUrl")
    @ApiOperation(value = "根据手机获取公司车队列表", notes = "根据手机获取公司车队列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Fleet.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<Fleet>> getFleetListByMobileUrl(@RequestBody  String tenantId) {
        LOGGER.info("FleetController.getFleetListByMobileUrl（根据手机获取公司车队列表） params : {} ", tenantId);

        RestfulResponse<List<Fleet>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            List<Fleet> fleets = fleetService.selectFleetListByMobile(tenantId);
            result.setData(fleets);
        } catch (BaseException e) {
            LOGGER.error("FleetController.getFleetListByMobileUrl ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.getFleetListByMobileUrl ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/queryPersonalByFleetName")
    @ApiOperation(value = "根据车队名查询车队联系人", notes = "根据车队名查询车队联系人", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestfulResponse<Map<String, Object>> queryPersonalByFleetName(@RequestBody Map<String,String> condition) {
        LOGGER.info("FleetController.queryPersonalByFleetName param : {}", condition);
        RestfulResponse<Map<String, Object>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            if (condition.get("fleetName")!=null){
                result.setData(fleetService.queryPersonalByFleetName(condition.get("fleetName")));
            }

        } catch (BaseException e) {
            LOGGER.error("FleetController.queryPersonalByFleetName ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.queryPersonalByFleetName ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }


    @PostMapping(value = "/queryByFleetName")
    @ApiOperation(value = "根据车队名查询车队", notes = "根据车队名查询车队", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestfulResponse<List<Fleet>> queryByFleetName(@RequestBody Map<String,String> condition) {
        LOGGER.info("FleetController.queryByFleetName param : {}", condition);
        RestfulResponse<List<Fleet>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            if (condition.get("corpName")!=null){
                List<Fleet> fleets = fleetService.queryByFleetName(condition.get("corpName"));
                result.setData(fleets);
            }

        } catch (BaseException e) {
            LOGGER.error("FleetController.queryByFleetName ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.queryByFleetName ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }



    @PostMapping(value = "/disableFleet")
    @ApiOperation(value = "禁用车队", notes = "禁用车队", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<String> disableFleet(@RequestBody FleetVo condition, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("FleetController.disableFleet（禁用车队） params : {} ", condition);
        RestfulResponse<String> result =new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(),null);
        try {
            result.setData(fleetService.disableFleet(condition,authorization));
        } catch (BaseException e) {
            LOGGER.error("FleetController.disableFleet... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.disableFleet ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/enableFleet")
    @ApiOperation(value = "启用车队", notes = "启用车队", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<String> enableFleet(@RequestBody FleetVo condition, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("FleetController.enableFleet（启用车队） params : {} ", condition);
        RestfulResponse<String> result =new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(),null);
        try {
            result.setData(fleetService.enableFleet(condition,authorization));
        } catch (BaseException e) {
            LOGGER.error("FleetController.enableFleet... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.enableFleet ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/lspFleetList")
    @ApiOperation(value = "获取车队列表", notes = "获取车队列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = FleetLineVO.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<FleetVo>> lspFleetList(@RequestBody Page<Map<String,Objects>> page,
                                                               @RequestHeader("Authorization") String authorization) {
        LOGGER.info("FleetController.lspFleetList（获取车队列表） params : {} ", page);
        RestfulResponse<Page<FleetVo>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            Page<FleetVo> pageVo = fleetService.lspFleetList(page, authorization);
            result.setData(pageVo);
        } catch (BaseException e) {
            LOGGER.error("FleetController.lspFleetList ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("FleetController.lspFleetList ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

}
